/* @(#)Encrypt.java   
 *
 * Project: GS
 *
 * Modify Information:
 * =============================================================================
 *   Author       Date       Description
 *   ------------ ---------- ---------------------------------------------------
 *   Jenny Li    2006-3-30     新增
 *
 * Copyright Notice:
 * =============================================================================
 *    Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room, 
 *        Science & Technology Building, No. 9 South Street, Zhong Guan Cun, 
 *        Haidian District, Beijing ,100081, China All rights reserved.
 *
 *    This software is the confidential and proprietary information of
 *        Beijing HiTRUST Technology Co., Ltd. ("Confidential Information").
 *        You shall not disclose such Confidential Information and shall use it
 *        only in accordance with the terms of the license agreement you entered
 *        into with HiTRUST.
 *
 * Warning:
 * =============================================================================
 * 
 */
package com.hitrust.gs.util.security;

import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.util.Base64;

/**
 * 
 */
public class Encryptor {

    final static byte[] keyBytes = {0x11, 0x22, 0x4F, 0x58, (byte)0x88, 0x10, 0x40, 0x38
            , 0x28, 0x25, 0x79, 0x51, (byte)0xCB, (byte)0xDD, 0x55, 0x66
            , 0x77, 0x29, 0x74, (byte)0x98, 0x30, 0x40, 0x36, (byte)0xE2};   //24字节的密钥
    public static Base64 bs = new Base64();
    
    public static void main(String[] args) {
        String x = encrypt("111111");
        System.out.println(x);
        x = decrypt(x);
        System.out.println(x);
    }

    /**
     * 执行加密，返回加密后的字符串
     * 
     * @param password
     * @return
     */
    public static String encrypt(String password) {
        String returnValue = "";
        try {
            byte[] bt = password.getBytes();
            bt = EncryptorUtil.encryptMode(keyBytes,bt);
            
            returnValue = bs.encode(bt);
//            returnValue = new String(bt);
        }
        catch (Exception ex) {
            GSLogWriter.error("密码加密异常");
        }
        return returnValue;
    }

    public static String decrypt(String enpwd){
        String returnValue = "";
        try{
            
            byte[] bt = bs.decode(enpwd);
            bt = EncryptorUtil.decryptMode(keyBytes,bt);
            returnValue = new String(bt);
        }catch(Exception e){
            GSLogWriter.error("解密异常");
        }
        return returnValue;
    }
}
